package cn.zhaoyuening.hadoopdemo.utils;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

public class RunUtils {
    public static void upload(String localStr,String hdfsStr) throws IOException {
        Configuration conf = ConfigureFactory.getConfiguration();
        FileSystem fileSystem = FileSystem.get(conf);
        Path hdfsPath = new Path(hdfsStr);
        Path localPath = new Path(localStr);

        boolean isExists = fileSystem.exists(hdfsPath);
        if (isExists) {
            fileSystem.delete(hdfsPath,true);
        }
        fileSystem.copyFromLocalFile(localPath, hdfsPath);
        fileSystem.close();
    }

}
